#!/usr/bin/env python
# -*- coding: latin-1; py-indent-offset:4 -*-
################################################################################
# 
# This file is part of Bfplusplus
#
# Bfplusplus is a graphical interface to the Betfair Betting Exchange
# Copyright (C) 2010 Daniel Rodriguez (aka Daniel Rodriksson)
# Copyright (C) 2011 Sensible Odds Ltd.
#
# You can learn more and contact the author at:
#
#    http://code.google.com/p/bfplusplus/
#
# Bfplusplus is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Bfplusplus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Bfplusplus. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################

from bfobj import MarketTuple

if True:
    def init(self):
        self.optNet = self.config.ReadBool('Optimize Network', False)
        self.config.WriteBool('Optimize Network', self.optNet)
        self.m_checkBoxOptimizeNetwork.SetValue(self.optNet)

        self.optNetGuard = self.config.ReadInt('Optimize Network - Guard', 10)
        self.config.WriteInt('Optimize Network - Guard', self.optNetGuard)
        self.m_spinCtrlOptimizeGuard.SetValue(self.optNetGuard)

        self.saveCount = self.optNetGuard
        self.saveCountPNL = int(self.optNetGuard / 2) + 1


    def OnSpinCtrlOptimizeGuard(self, event):
        self.optNetGuard = self.m_spinCtrlOptimizeGuard.GetValue()
        self.config.WriteInt('Optimize Network - Guard', self.optNetGuard)

        self.saveCount = self.optNetGuard
        self.saveCountPNL = int(self.optNetGuard / 2) + 1


    def OnCheckBoxOptimizeNetwork(self, event):
        if self.marketTuple is None:
            return

        marketComp = self.marketCache[self.marketTuple]

        self.optNet = self.m_checkBoxOptimizeNetwork.GetValue()

        if self.optNet:
            self.saveCount = self.optNetGuard
            self.saveCountPNL = int(self.optNetGuard / 2) + 1
        else:
            if not self.marketStopped:
                self.GetMUBets(MarketTuple(marketComp.exchangeId, marketComp.marketId))
                self.GetMarketProfitAndLoss(MarketTuple(marketComp.exchangeId, marketComp.marketId))

        self.config.WriteBool('Optimize Network', self.optNet)
